<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class article extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'songshu:article {id}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '推送一篇文章';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $id = $this->argument('id');
        $info = DB::table('check_article_queue')->where('id',$id)->first();
        $article = DB::connection('db2')->table('article')->where('id',$info->article_id)->first();
        $data = [
            'g_id'=>0,
            'top'=>$article->top,
            'set_top'=>$article->set_top,
            'title'=>$article->title,
            'content'=>$article->content,
            'pic'=>$article->pic,
            'type'=>$article->type,
            'is_hot'=>$article->is_hot,
            'show_pv'=>$article->show_pv,
            'pv'=>$article->pv,
            'pv_max'=>$article->pv_max,
            'money'=>$article->money,
            'day'=>time(),
            'status'=>0,
            'downline'=>1,
            'source'=>$article->source,
            'type_of_article'=>$article->type_of_article,
            'length_time'=>$article->length_time,
            'grab'=>$article->grab,
            'primary_url'=>$article->primary_url,
            'ar_source'=>$article->ar_source,
            'words_number'=>$article->words_number,
        ];
        $aid = DB::table('article')->insertGetId($data);
        if($aid){
            DB::connection('db2')->table('article')->where('id',$info->article_id)->update([
                'status'=>0,
                'downline'=>1,
            ]);
            DB::table('check_article_queue')->where('id',$id)->update([
                'exec'=>1,
                'exec_time'=>time(),
                'aid'=>$aid,
            ]);
            $key = config('rediskey.article_params_zero')[$article->type];
            Redis::zadd($key,time(),$aid);
            echo $aid."\n";
            echo $key."\n";
            echo Redis::zscore($key,$aid)."\n";
        }else{
            echo 'adi not found';
        }
    }
}
